/**
*
*   class Subject
*
*   stores information about a group of students
*
*   @author Ranie Jade Ramiso
*
*/

#ifndef STUDENTGROUP_H_INCLUDED
#define STUDENTGROUP_H_INCLUDED
#include <vector>
#include "subject.h"

class StudentGroup{
public:
    //! a vector/list of subjects
    typedef std::vector<Subject*> SubjectList;

    //! constructor
    StudentGroup(const char* name, const int size, const int id){
        mName = name;
        mSize = size;
        mId = id;
    }

    //! returns group's name
    inline const char* name() const { return mName.c_str(); }
    //! returns group's size
    inline int size() const { return mSize; }
    //! returns group's id
    inline int id() const { return mId; }

    inline SubjectList subjects() const { return mList; }


    inline void setName(const char* name) { mName = name;}
    //! set the group's size
    inline void setSize(const int size) { mSize = size; }

    //! add a subject to the group's subject list
    bool addSubject(Subject &subject);
    //! remove a subject with the id 'id' from the group's subject list
    bool removeSubject(const int id);

private:
    std::string mName;
    int mSize;
    int mId;
    SubjectList mList;
};

bool StudentGroup::addSubject(Subject &subject){
    SubjectList::const_iterator it = mList.begin();
    SubjectList::const_iterator end = mList.end();

    while(it!=end){
        if((*it)->id() == subject.id())
            return false;
        it++;
    }

    mList.push_back(&subject);
    return true;
}

bool StudentGroup::removeSubject(const int id){
    SubjectList::iterator it = mList.begin();
    SubjectList::iterator end = mList.end();

    while(it!=end){
        if((*it)->id() == id){
            mList.erase(it);
            return true;
        }
        it++;
    }
    return false;
}

#endif // STUDENTGROUP_H_INCLUDED
